#pragma strict

//间隔时间
var interval:float;
var objGame:Transform;
var player=0;
var playerobj:GameObject;
static var initplaylift:float;
static var playerLife=0f;
static var integral=0;
static var isDeath=false;
function Start () {
	//InvokeRepeating("InitPosition",3,interval);
	StartCoroutine(InitPosition());
}

function Update () {
	
	if(isDeath)
	{
		TryAgen();
	}
}

function OnGUI()
{
	GUI.Label(Rect(20,10,120,20),"生命值："+playerLife);
	GUI.Label(Rect(20,35,120,20),"命值："+player);
	GUI.Label(Rect(20,60,120,20),"积分："+integral);
}

function InitPosition()
{
	while (true) {
		yield WaitForSeconds(interval);
		//Debug.Log("shua");
		Instantiate(objGame);
	}
}

function TryAgen()
{
	player--;
	isDeath=false;
	//如果命值还在则1.5秒重生，否则死亡
	if(player>0)
	{
		yield WaitForSeconds(1.5f);
		playerLife=initplaylift;
		Instantiate(playerobj);
	}else{
		GameOver.aglive="Level01";
		GameOver.integral=integral;
		Application.LoadLevel("GameOver");
	}
}
